package stu.aistar.util;

/**
 * 自定义日期的工具类 - 推荐定义为static
 */
public class DateUtil {
    /**
     * 获取某月的天数
     * @param year
     * @param month
     * @return
     */
    public static int getMaxDay(int year,int month){
        int day = 0;
        if (month == 1||month == 3||month == 5||month == 7||month == 8||month == 10||month == 12){
            day = 31;
        }else if (month == 2){
            day = isRunNian(year)?29:28;
        }else {
            day = 30;
        }
        return day;
    }

    /**
     * 判断是否为闰年
     * @param year
     * @return
     */
    public static boolean isRunNian(int year){
        return ((year%4 == 0 && year%100 != 0) || year %400 == 0);
    }
}
